﻿using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.ObjectMapping;
using XCWechat.Contexts;
using XCWechat.Dtos;
using XCWechat.Entities.Clients;

namespace XCWechat.Repositories
{
    [Dependency(ServiceLifetime.Transient)]
    public class ClientInfoRepository : EfCoreRepository<XCWechatDbContext, ClientInfo, Guid>, IClientInfoRepository
    {
        public XCWechatDbContext dbContext { get; set; }
        public IObjectMapper mapper { get; set; }
        public ClientInfoRepository(IDbContextProvider<XCWechatDbContext> dbContextProvider) : base(dbContextProvider)
        {
        }

        public async Task<ClientInfoDto> GetClientInfoAsync(Guid id)
        {
            ClientInfo clientInfo = dbContext.ClientInfos.FirstOrDefault(c => c.Id == id);
            if (clientInfo != null)
            {
                ClientInfoDto clientInfoDto = mapper.Map<ClientInfo, ClientInfoDto>(clientInfo);
                return clientInfoDto;
            }
            return new ClientInfoDto();
        }

        public async Task<ClientInfo> GetClientInfoAsync()
        {
            ClientInfo clientInfo = dbContext.ClientInfos.FirstOrDefault();
            return clientInfo;
        }
    }
}
